#include "WorldEntity.h"

CWorldEntity::CWorldEntity(void){}

CWorldEntity::~CWorldEntity(void){}

/*function that test if the entity collide with otherEntity. It returns true if there is a collision.*/
bool CWorldEntity::checkForCollision(CWorldEntity* otherEntity)
{
	CRectangle self = this->collisionRectangle;
	self.setBottom(self.getBottom()+this->currentPosY);
	self.setTop(self.getTop()+this->currentPosY);
	self.setLeft(self.getLeft()+this->currentPosX);
	self.setRight(self.getRight()+this->currentPosX);

	CRectangle entity=otherEntity->getCollisionRectangle();
	entity.setBottom(entity.getBottom()+otherEntity->currentPosY);
	entity.setTop(entity.getTop()+otherEntity->currentPosY);
	entity.setLeft(entity.getLeft()+otherEntity->currentPosX);
	entity.setRight(entity.getRight()+otherEntity->currentPosX);

	if((self.getRight()<entity.getLeft()) || (self.getLeft()>entity.getRight()) ||
		(self.getBottom()<entity.getTop()) || (self.getTop()>entity.getBottom()) )
	{
		return false;
	}
	else
	{
		return true;
	}
}

/*function that test if the entity is an enemy of otherEntity. It returns true if they are enemies.*/
bool CWorldEntity::isEnemyOf(CWorldEntity* otherEntity)
{
	if(this->side==otherEntity->getSide() || otherEntity->getSide()==eSideNeutral)
	{
		return false;
	}
	else
	{
		return true;
	}
}
int CWorldEntity::getCurrentPosX(void) const
{
	return this->currentPosX;
}
int CWorldEntity::getCurrentPosY(void) const
{
	return this->currentPosY;
}
int CWorldEntity::getPreviousPosX(void) const
{
	return this->previousPosX;
}
int CWorldEntity::getPreviousPosY(void) const
{
	return this->previousPosY;
}
int CWorldEntity::getIndexSprite(void) const
{
	return this->indexSprite;
}
int CWorldEntity::getIndexFrame(void) const
{
	return this->indexFrame;
}
int CWorldEntity::getSpeed(void) const
{
	return this->speed;
}
int CWorldEntity::getCurrentHealth(void) const
{
	return this->currentHealth;
}
int CWorldEntity::getCollisionCost(void) const
{
	return this->collisionCost;
}
bool CWorldEntity::getActive(void) const
{
	return this->active;
}
int CWorldEntity::getSide(void) const
{
	return this->side;
}
CRectangle CWorldEntity::getCollisionRectangle(void)const
{
	return this->collisionRectangle;
}
void CWorldEntity::setCurrentPosX(int posX)
{
	this->currentPosX=posX;
}
void CWorldEntity::setCurrentPosY(int posY)
{
	this->currentPosY=posY;
}
void CWorldEntity::setPreviousPosX(int posX)
{
	this->previousPosX=posX;
}
void CWorldEntity::setPreviousPosY(int posY)
{
	this->previousPosY=posY;
}
void CWorldEntity::setIndexSprite(int indexSprite)
{
	this->indexSprite=indexSprite;
}
void CWorldEntity::setIndexFrame(int indexFrame)
{
	this->indexFrame=indexFrame;
}
void CWorldEntity::setSpeed(int speed)
{
	this->speed=speed;
}
void CWorldEntity::setCurrentHealth(int health)
{
	this->currentHealth=health;
}
void CWorldEntity::setCollisionCost(int collisionCost)
{
	this->collisionCost=collisionCost;
}
void CWorldEntity::setActive(bool active)
{
	this->active=active;
}
void CWorldEntity::setSide(int side)
{
	this->side=side;
}
void CWorldEntity::setCollisionRectangle(CRectangle collisionRectangle)
{
	this->collisionRectangle=collisionRectangle;
}
int CWorldEntity::getState(void)
{
	return -1;
}
int CWorldEntity::getNumberOfLife(void)
{
	return -1;
}
int CWorldEntity::getTotalHealth(void)
{
	return -1;
}
void CWorldEntity::die(void)
{
	this->active=false;
}